function HandlePageExpenseCash(gui, operator, now, options) {
  this._gui = gui;
  this._operator = operator;
  this._now = now;
  this._options = options;
  this._nowstamp = (options && options.nowstamp) ? options.nowstamp : null;
  
  this._page = 1;
  this._order = 'd.e_oid';
  this._queue = 'ASC';
  this._search = DlmanageUtils.acctExpenseSearch();
  this._lag = 0;
  if (this._nowstamp) {
    this._lag = SimpleDate.toStamp(SimpleDate.create(this._now.year, this._now.month, this._now.date)) - this._nowstamp;
  }
  this._createElements();
};

HandlePageExpenseCash.prototype._createElements = function() {
  var _self = this;
  this._popupBox = new PopupBox();
  this._popupBox2 = new PopupBox2();
  
  this._cond = '(d.method = \'C\') AND (d.status = 2)';
  
  tr = this._gui.mains.insertRow(-1);
  td = tr.insertCell(-1);
  td.style.backgroundColor = '#fff';
  td.colSpan = 12;
  td.appendChild(DOMUtils.getLoadingImage());
  
  this._loadData();
};

HandlePageExpenseCash.prototype._loadData = function() {
  this._results = null;
  this._expenses = null;
  this._exps = null;
  this._parameters = null;
  this._retrieveExpenses();
  this._retrieveResults();
  this._retrieveExps();
};

HandlePageExpenseCash.prototype._verifyData = function() {
  if (this._results && this._expenses && this._exps) {
    this._updateElements();
  }
};

HandlePageExpenseCash.prototype._retrieveResults = function(pos) {
  var _self = this;
  var condition = HandleSearchAuditExpense.toSql(this._search, this._lag) + ' AND ' + this._cond;
  var args = '&c=' + encodeURIComponent(condition);
  /*new RequestUtils()._custom('acctexpense', args, function(result, params) { _self._results = result;
                                                                              _self._verifyData.call(_self);
                                                                            }, { pos: (pos) ? pos : null });
*/
  new RequestUtils()._mysql('ieexpense', args, function(result, params) { _self._results = result;
                                                                           _self._verifyData.call(_self);
                                                                         }, {php:'customphp/mysqlcustom.php', pos: ((pos) ? pos : null) });

};

HandlePageExpenseCash.prototype._retrieveExpenses = function(pos) {
  var _self = this;
  var condition = HandleSearchAuditExpense.toSql(this._search, this._lag) + ' AND ' + this._cond;
  /*new RequestUtils()._read('expense', null, condition, this._page, 20, this._order, this._queue, function(result, params) { _self._expenses = result.data;
                                                                                                                            _self._parameters = result;
                                                                                                                            _self._verifyData.call(_self);
                                                                                                                          }, { pos: (pos) ? pos : null });
*/
  var args = ((condition) ?  '&c=' + condition : '') + '&p=' + this._page + '&s=20' + '&o=' + this._order + '&q=' + this._queue;
  new RequestUtils()._mysql('expenses', args, function(result, params) { _self._expenses = result.data;
                                                                           _self._parameters = result;
                                                                           _self._verifyData.call(_self);
                                                                         }, {php:'customphp/mysqlcustom.php', pos: ((pos) ? pos : null) });
};

HandlePageExpenseCash.prototype._retrieveExps = function(pos) {
  var _self = this;
  /*new RequestUtils()._read('expense', null, null, null, null, null, null, function(result, params) { _self._exps = result.data;
                                                                                                      _self._verifyData.call(_self);
                                                                                                    }, null);
*/
  new RequestUtils()._mysql('expense', null, function(result, params) { _self._exps = result.data;
                                                                           _self._verifyData.call(_self);
                                                                         }, {php:'customphp/mysqlread.php', pos: ((pos) ? pos : null) });

};

HandlePageExpenseCash.prototype._updateElements = function() {
  var _self = this;
  DlmanageUtils.clear(this._gui.search);
  DOMUtils.removeChildElements(this._gui.totalCash);
  DOMUtils.removeChildElements(this._gui.pagination);
  DOMUtils.removeTableRows(this._gui.mains, 1);
  var unique = MiscUtils.unique();
  DOMUtils.removeChildElements(this._gui.checkAll);
  this._selects = [];

  this._gui.totalCash.appendChild(document.createTextNode('$' + parseFloat(this._results.expense).toFixed(2)));
  this._gui.verify.onclick = function() { if (_self._selects.length == 0) {
                                            window.alert('No Items Selected');
                                            return;
                                          }
                                          var exps = [];
                                          for (var i = 0, il = _self._selects.length; i <il; i++) {
                                            var exp = _self._selects[i];
                                            exp.status = 3;
                                            exps[exps.length] = exp;
                                          }
                                          new RequestUtils()._mwrite('expense', exps, [], function() { _self._retrieveResults(1); _self._retrieveExpenses(_self._parameters.page, _self._parameters.condition); } , { pos: DOMUtils.findPos(this) });
                                        };
  
  if (this._expenses.length == 0) {
    tr = this._gui.mains.insertRow(-1);
    tr.className = 'roweven';
    td = tr.insertCell(-1);
    td.colSpan = 12;
    td.style.height = '24px';
    td.style.textAlign = 'center';
    td.appendChild(document.createTextNode('N/A'));
  }

  for (var i = 0, il = this._expenses.length; i < il; i++) {
    var expense = this._expenses[i];
    tr = this._gui.mains.insertRow(-1);
    tr.className = (tr.rowIndex % 2 == 0) ? 'roweven' : 'rowodd';
    
    td = tr.insertCell(-1);
    td.style.borderRight = 'solid 1px #885b5d';
    td.style.textAlign = 'center';
    var check = DOMUtils.createInput('', unique + '_' + i, 'checkbox', '', null);
    check._expense = expense;
    check.onclick = function() { if (this.checked == true) {
                                   _self._selects[_self._selects.length] = this._expense;
                                 } else {
                                   MiscUtils.remove(_self._selects, this._expense, 'trackId');
                                 }
                               };
    td.appendChild(check);
    
    td = tr.insertCell(-1);
    td.style.height = '25px';
    td.style.borderRight = 'solid 1px #885b5d';
    td.style.textAlign = 'center';
    td.appendChild(document.createTextNode(SimpleDate.format(expense.createdDate)));
    
    td = tr.insertCell(-1);
    td.style.textAlign = 'center';
    td.style.borderRight = 'solid 1px #885b5d';
    td.appendChild(document.createTextNode(SimpleDate.format(expense.payDate)));
    
    td = tr.insertCell(-1);
    td.style.borderRight = 'solid 1px #885b5d';
    td.style.textAlign = 'left';
    td.style.padding = '0 0 0 10px';
    td.appendChild(document.createTextNode(expense.payee));
    
    td = tr.insertCell(-1);
    td.style.borderRight = 'solid 1px #885b5d';
    td.style.textAlign = 'left';
    td.style.padding = '0 0 0 10px';
    td.appendChild(document.createTextNode(expense.particular));
    
    td = tr.insertCell(-1);
    td.style.borderRight = 'solid 1px #885b5d';
    td.style.textAlign = 'left';
    td.style.padding = '0 0 0 10px';
    td.appendChild(document.createTextNode('$' + expense.amount));
    
    td = tr.insertCell(-1);
    td.style.borderRight = 'solid 1px #885b5d';
    td.style.textAlign = 'center';
    td.appendChild(document.createTextNode(expense.method));
    
    td = tr.insertCell(-1);
    td.style.borderRight = 'solid 1px #885b5d';
    td.style.textAlign = 'left';
    td.style.padding = '0 0 0 10px';
    td.appendChild(document.createTextNode(expense.chequeNumber));
    
    td = tr.insertCell(-1);
    td.style.borderRight = 'solid 1px #885b5d';
    td.style.textAlign = 'center';
    td.appendChild(document.createTextNode((expense.ng == 1) ? 'Y' : 'N'));
    
    td = tr.insertCell(-1);
    td.style.borderRight = 'solid 1px #885b5d';
    td.style.textAlign = 'center';
    td.appendChild(document.createTextNode((expense.ne == 1) ? 'Y' : 'N'));
    
    td = tr.insertCell(-1);
    td.style.borderRight = 'solid 1px #885b5d';
    td.style.textAlign = 'left';
    td.style.padding = '0 0 0 10px';
    if (expense.note.length > 30) {
      td.appendChild(document.createTextNode(expense.note.substring(0, 30) + '...'));
      td.style.whiteSpace = 'nowrap';
      var a = document.createElement('a');
      a.href = '#';
      a._expense = expense;
      a.appendChild(document.createTextNode('all'));
      a.onclick = function() { MiscUtils.alert(_self._popupBox, DOMUtils.findPos(this), this._expense.note); return false;};
      td.appendChild(a);
    } else {
      td.appendChild(document.createTextNode(expense.note));
      if (expense.note.length == 0) {
        td.appendChild(document.createTextNode('(none)'));
      }
    }
    td = tr.insertCell(-1);
    td.style.borderRight = 'solid 1px #885b5d';
    td.style.textAlign = 'center';
    var remove = document.createElement('img');
    remove.src = 'images/common/delete.png';
    remove.style.cursor = 'pointer';
    remove._expense = expense;
    remove.onclick = function() { var pos = DOMUtils.findPos(this);
                                  var div = document.createElement('div');
                                  var expense = this._expense
                                  var func1 = function() { expense.status = -1;
                                                           expense.cancelledDate = _self._now;
                                                           expense.cancelledOperator = _self._operator.account;
                                                           expense.cancelledMessage = expense._text;
                                                           new RequestUtils()._mwrite('expense', [expense], [], function() { _self._retrieveResults(1); _self._retrieveExpenses(_self._parameters.page, _self._parameters.condition); }, { pos: pos });
                                                           _self._popupBox2._close();
                                                         };
                                  var func2 = function() { _self._popupBox2._close(); };
                                  MiscUtils.dialog(_self._popupBox2, pos, div, func1, func2, {t: 'Cancel Reason'});
                                  new DialogInput(div, expense, { title: '' });
                                  return false;
                                };
    td.appendChild(remove);
  }
  
  this._gui.checkAll.checked = false;
  this._gui.checkAll._unique = unique;
  this._gui.checkAll.onclick = function() { if (this.checked == true) {
                                             for (var i = 0, il = _self._expenses.length; i < il; i++) {
                                                var object = _self._expenses[i];
                                                if (document.getElementById(this._unique + '_' + i) && !document.getElementById(this._unique + '_' + i).checked) {
                                                  _self._selects[_self._selects.length] = object;
                                                  document.getElementById(this._unique + '_' + i).checked = true;
                                                }
                                              }
                                            } else {
                                              for (var i = 0, il = _self._expenses.length; i < il; i++) {
                                                var object = _self._expenses[i];
                                                if (document.getElementById(this._unique + '_' + i)) {
                                                  MiscUtils.remove(_self._selects, object, 'trackId');
                                                  document.getElementById(this._unique + '_' + i).checked = false;
                                                }
                                              }
                                            }
                                          };
  
  Pagination.makePagedResults(this._gui.pagination, this._parameters.page, this._parameters.total, this._parameters.size, function(page) { _self._page = page; _self._retrieveExpenses.call(_self); }, this, document);
  
  new HandleSearchAuditExpense(this._gui.search, this._operator, this._now, { cond: this._cond, items: this._exps, search: this._search, callbackFunc: function(search) { _self._search = search; _self._page = 1; _self._retrieveResults.call(_self); _self._retrieveExpenses.call(_self); } });

};

HandlePageExpenseCash.prototype._changeDate = function(label, currentDate, onChangeFunc, showTime) {
  var _self = this;
  this._wContainer = document.createElement('div');
  this._wContainer.style.left = DOMUtils.findPos(label)[0] + 'px';
  this._wContainer.style.top = DOMUtils.findPos(label)[1] + 'px';
  this._popupBox._open(this._wContainer, { pos: DOMUtils.findPos(label) });
  
  var ds = new DateSelect(currentDate, null, { container: this._wContainer, showTime: showTime });
  ds._selectFunc = function(sd) { _self._selectDate.call(_self, sd, label, onChangeFunc, showTime); };
};

HandlePageExpenseCash.prototype._selectDate = function(sd, label, onChangeFunc, showTime) {
  
  onChangeFunc(sd);
  this._showDate(sd, label, showTime);
  this._popupBox._close();
};

HandlePageExpenseCash.prototype._showDate = function(sd, label, showTime) {
  if (sd) { 
    label.value = SimpleDate.format(sd, showTime);
  } else {
    label.value = '';
  }
};